36 #include "sensor_io_i2c.h" 38 #include "fxos8700_drv.h" 42 #define FXOS8700_ACCEL_FIFO_SIZE 32 43 #define FXOS8700_MAG_FIFO_SIZE 1
48 { .readFrom = FXOS8700_WHO_AM_I, .numBytes = 1 }, __END_READ_DATA__
54 { .readFrom = FXOS8700_STATUS, .numBytes = 1 }, __END_READ_DATA__
60 { .readFrom = FXOS8700_OUT_X_MSB, .numBytes = 6 }, __END_READ_DATA__
69 { FXOS8700_CTRL_REG1, 0x00, 0x00 },
73 { FXOS8700_F_SETUP, 0x40, 0x00 },
81 { FXOS8700_M_CTRL_REG1, 0x1F, 0x00 },
90 { FXOS8700_M_CTRL_REG2, 0x00, 0x00 },
100 { FXOS8700_XYZ_DATA_CFG, 0x01, 0x00 },
108 { FXOS8700_CTRL_REG2, 0x02, 0x00 },
124 #if (ACCEL_ODR_HZ <= 1) // select 0.78Hz ODR 125 { FXOS8700_CTRL_REG1, 0x3D, 0x00 },
126 #elif (ACCEL_ODR_HZ <= 3) // select 3.125Hz ODR 127 { FXOS8700_CTRL_REG1, 0x35, 0x00 },
128 #elif (ACCEL_ODR_HZ <= 6) // select 6.25Hz ODR 129 { FXOS8700_CTRL_REG1, 0x2D, 0x00 },
130 #elif (ACCEL_ODR_HZ <= 30) // select 25Hz ODR 131 { FXOS8700_CTRL_REG1, 0x25, 0x00 },
132 #elif (ACCEL_ODR_HZ <= 50) // select 50Hz ODR 133 { FXOS8700_CTRL_REG1, 0x1D, 0x00 },
134 #elif (ACCEL_ODR_HZ <= 100) // select 100Hz ODR 135 { FXOS8700_CTRL_REG1, 0x15, 0x00 },
136 #elif (ACCEL_ODR_HZ <= 200) // select 200Hz ODR 137 { FXOS8700_CTRL_REG1, 0x0D, 0x00 },
138 #else // select 400Hz ODR 139 { FXOS8700_CTRL_REG1, 0x05, 0x00 },
144 #define FXOS8700_COUNTSPERG 8192.0 145 #define FXOS8700_COUNTSPERUT 10 155 status = Register_I2C_Read(sensor->
bus_driver, sensor->
addr, FXOS8700_WHO_AM_I, 1, ®);
157 if (status==SENSOR_ERROR_NONE) {
159 sfg->Accel.iWhoAmI = reg;
169 if (reg != FXOS8700_WHO_AM_I_PROD_VALUE) {
170 return SENSOR_ERROR_INIT;
183 sfg->Accel.isEnabled =
true;
198 uint8_t sensor_fifo_count;
203 return SENSOR_ERROR_INIT;
208 if (status != SENSOR_ERROR_NONE)
return(status);
210 sensor_fifo_count = I2C_Buffer[0] & 0x3F;
213 if (sensor_fifo_count == 0)
return(SENSOR_ERROR_READ);
220 if (status==SENSOR_ERROR_NONE) {
221 for (j = 0; j < sensor_fifo_count; j++) {
222 sample[
CHX] = (I2C_Buffer[6 * j] << 8) | (I2C_Buffer[6 * j + 1]);
223 sample[
CHY] = (I2C_Buffer[6 * j + 2] << 8) | (I2C_Buffer[6 * j + 3]);
224 sample[
CHZ] = (I2C_Buffer[6 * j + 4] << 8) | (I2C_Buffer[6 * j + 5]);
238 uint8_t I2C_Buffer[6];
244 return SENSOR_ERROR_INIT;
251 if (status==SENSOR_ERROR_NONE) {
253 sample[
CHX] = (I2C_Buffer[0] << 8) | I2C_Buffer[1];
254 sample[
CHY] = (I2C_Buffer[2] << 8) | I2C_Buffer[3];
255 sample[
CHZ] = (I2C_Buffer[4] << 8) | I2C_Buffer[5];
270 sts1 = FXOS8700_ReadAccData(sensor, sfg);
287 { FXOS8700_CTRL_REG1, 0x00, 0x01 },
303 sfg->Accel.isEnabled =
false;
309 return SENSOR_ERROR_INIT;
#define FXOS8700_COUNTSPERUT
const registerwritelist_t FXOS8700_FULL_IDLE[]
#define CHY
Used to access Y-channel entries in various data data structures.
#define FXOS8700_ACCEL_FIFO_SIZE
FXOS8700 (accel), MMA8652, FXLS8952 all have 32 element FIFO.
#define FXOS8700_COUNTSPERG
int8_t FXOS8700_Read(PhysicalSensor *sensor, SensorFusionGlobals *sfg)
void addToFifo(FifoSensor *sensor, uint16_t maxFifoSize, int16_t sample[3])
addToFifo is called from within sensor driver read functions
The top level fusion structure.
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
#define MAG_FIFO_SIZE
FXOS8700 (mag), MAG3110 have no FIFO so equivalent to 1 element FIFO.
int16_t iCountsPeruT
counts per uT
#define ACCEL_FIFO_SIZE
FXOS8700 (accel), MMA8652, FXLS8952 all have 32 element FIFO.
MagSensor Mag
magnetometer storage
int8_t FXOS8700_ReadMagData(PhysicalSensor *sensor, SensorFusionGlobals *sfg)
The FifoSensor union allows us to use common pointers for Accel, Mag & Gyro logical sensor structures...
int8_t FXOS8700_Init(PhysicalSensor *sensor, SensorFusionGlobals *sfg)
float fuTPerCount
uT per count
bool isEnabled
true if the device is sampling
The sensor_fusion.h file implements the top level programming interface.
const registerreadlist_t FXOS8700_WHO_AM_I_READ[]
const registerreadlist_t FXOS8700_F_STATUS_READ[]
Provides function prototypes for driver level interfaces.
const registerwritelist_t FXOS8700_Initialization[]
#define CHX
Used to access X-channel entries in various data data structures.
void conditionSample(int16_t sample[3])
conditionSample ensures that we never encounter the maximum negative two's complement value for a 16-...
float fCountsPeruT
counts per uT
Application-specific status subsystem.
An instance of PhysicalSensor structure type should be allocated for each physical sensors (combo dev...
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
uint8_t iWhoAmI
sensor whoami
int8_t FXOS8700_Idle(PhysicalSensor *sensor, SensorFusionGlobals *sfg)
#define F_USING_ACCEL
nominally 0x0001 if an accelerometer is to be used, 0x0000 otherwise
SensorFusionGlobals sfg
This is the primary sensor fusion data structure.
uint16_t addr
I2C address if applicable.
registerreadlist_t FXOS8700_DATA_READ[]